package info.niwota.home.fm;

import info.niwota.home.R;

import java.io.IOException;

import x.java.io.File;
import android.os.Bundle;
import android.view.View;


public class FileExploreActivity extends FileBrowseActivity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//
		//footer.setVisibility(View.VISIBLE);
		selected.setVisibility(View.GONE);
		buttons.setVisibility(View.GONE);
		//
		// last saved
		File f = readPath();
		changeTo(f);
	}
	
	protected void changeTo(File f) {
		if (f != null) {
			f.refresh();
			doSelectFolder(f);
		}
	}

	@Override
	protected void doFinish() {
		File f = selectedFolder;
		if (f.isRoot()) {
			savePath(f);;
		} else {
			doBack();
		}
	}

	@Override
	protected void setSelectedText(File newfile) {
		String p = newfile.getPath();
		String t = getString(R.string.app_name_selected, p);
		setTitle(t);
		//
		view(newfile);
	}

	protected void view(File file) {
		if (file.isFile()) {
			try {
				if (file.canExecute()) {
					file.execute();
					return;
				}
				perform(BinConstant.BIN_VIEW, file);
			} catch (IOException e) {
				onError(e);
			}
		}
	}
}